package io.geekidea.springbootplus.system.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.system.entity.SysProductAttribute;
import io.geekidea.springbootplus.system.mapper.SysProductAttributeMapper;
import io.geekidea.springbootplus.system.service.SysProductAttributeService;
import io.geekidea.springbootplus.system.vo.SysProductAttributeQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.Serializable;


@Service
@Transactional(rollbackFor = Exception.class)
public class SysProductAttributeServiceImpl extends BaseServiceImpl<SysProductAttributeMapper, SysProductAttribute> implements SysProductAttributeService {

    @Resource
    private SysProductAttributeMapper sysProductAttributeMapper;

    @Override
    public boolean saveSysProductAttribute(SysProductAttribute sysProductAttribute) throws Exception {
        return sysProductAttributeMapper.insert(sysProductAttribute) > 0;
    }

    @Override
    public boolean updateSysProductAttribute(SysProductAttribute sysProductAttribute) throws Exception {
        return sysProductAttributeMapper.updateById(sysProductAttribute) > 0;
    }

    @Override
    public boolean deleteSysProductAttribute(Integer id) throws Exception {
        return sysProductAttributeMapper.deleteById(id) > 0;
    }

    @Override
    public SysProductAttribute getSysProductAttributeById(Serializable id) throws Exception {
        return sysProductAttributeMapper.selectById(id);
    }

    @Override
    public Paging<SysProductAttributeQueryVo> getSysProductAttributePageList() throws Exception {
        Page<SysProductAttribute> page = new PageInfo<>(null, OrderItem.desc(getLambdaColumn(SysProductAttribute::getId)));
        IPage<SysProductAttributeQueryVo> iPage = sysProductAttributeMapper.getSysProductAttributePageList(page);
        return new Paging(iPage);
    }
}
